package com.yishusmt.mobsmt.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 邮件发送类
 *
 * @author zhangyi
 * @date 2018/8/8 11:21
 */
@Component
public class MailUtil {
    /**
     * 发送方
     */
    @Value("${spring.mail.username}")
    private String sender;

    @Autowired
    private JavaMailSender javaMailSender;

    /**
     *  发送简单邮件
     *
     * @param receiving 接受方地址
     * @param subject 主题
     * @param text 内容
     * @return
     */
    public void sendMessage(String receiving, String subject, String text){
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setFrom(sender);
            simpleMailMessage.setTo(receiving);
            simpleMailMessage.setSubject(subject);
            simpleMailMessage.setText(text);
            javaMailSender.send(simpleMailMessage);
    }
    /**
     *  发送附件邮件
     *
     * @param receiving 接受方地址
     * @param subject 主题
     * @param text 内容
     * @param files
     * @return
     */
    public void sendAttacmentMessage(String receiving, String subject, String text,File... files){
    }
}
